﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace _00_WPF基础.控件
{
	/// <summary>
	/// A19_DataGrid2.xaml 的交互逻辑
	/// </summary>
	public partial class A19_DataGrid2 : Window
	{
		public A19_DataGrid2()
		{
			InitializeComponent();
			MainViewModel viewModel1 = new MainViewModel();
			this.DataContext = viewModel1;
		}

		private void Window_Loaded(object sender, RoutedEventArgs e)
		{
		}
	}
	public class MainViewModel : INotifyPropertyChanged
	{
		private ObservableCollection<Person1> people;
		public ObservableCollection<Person1> People
		{
			get { return people; }
			set { people = value; OnPropertyChanged(); }
		}

		private List<City> cities;
		public List<City> Cities
		{
			get { return cities; }
			set { cities = value; OnPropertyChanged(); }
		}

		public MainViewModel()
		{
			Cities = new List<City> { new City { Name = "New York" }, new City { Name = "Los Angeles" }, new City { Name = "Chicago" } };
			People = new ObservableCollection<Person1>
			{
			new Person1 { Name = "John", City = new City { Name = "New York" } },
			new Person1 { Name = "Jane", City = new City { Name = "Los Angeles" } },
			new Person1 { Name = "Bob", City = new City { Name = "Chicago" } }
			};
		}

		public event PropertyChangedEventHandler PropertyChanged;
		protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
		{
			PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
		}
	}

	public class Person1
	{
		public string Name { get; set; }
		public City City { get; set; }
	}

	public class City
	{
		public string Name { get; set; }
	}
}

